package com.jcoinexchange.web.auth;

import com.alibaba.ttl.TransmittableThreadLocal;

/**
 * @author tony
 */
public class Auth {
    private final static  TransmittableThreadLocal<UserInfo> CURRENT_USER = new TransmittableThreadLocal<>();
    private final static TransmittableThreadLocal<String> CURRENT_AUTH_TOKEN = new TransmittableThreadLocal<>();

    public static void fill(UserInfo userInfo, String token){
        CURRENT_USER.set(userInfo);
        CURRENT_AUTH_TOKEN.set(token);
    }

    public static void clear(){
        CURRENT_USER.remove();
        CURRENT_AUTH_TOKEN.remove();
    }

    public static UserInfo getCurrentUser(){
        return CURRENT_USER.get();
    }

    public static String getCurrentAuthToken(){
        return CURRENT_AUTH_TOKEN.get();
    }

}
